// patrolnpc.txt
// Creature attacks anything it hates nearby, and spends the rest of its time patrolling a path.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - Number of path to follow.
//	 Cell 1 - If 0, just loops around path. If 1, walks to end of path, waits a little, and returns home.
//      If 2, goes to end of path and just stops.
//   Cell 2 - Node if talked to. 0 means no conversation
//   Cell 3,4 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

variables;

short i,target;
short pt_b = 0;
short sent_alert = 0;

body;

beginstate INIT_STATE;
	set_walk_speed(ME,22);
	set_aggression(ME,9);
	set_new_abil(ME,20);
	change_max_health(ME,200);
	set_boss_level(ME,1);
	break;

beginstate DEAD_STATE;
	if ((what_group_in(ME) >= 0) && (sent_alert == 0) && (get_attitude(ME) >= 10)) {
		set_attitude(1000 + what_group_in(ME),10);
		alert_char(1000 + what_group_in(ME));
		set_act_at_dist(1000 + what_group_in(ME),1);
		}
break;

beginstate START_STATE;
	if (get_foe_target(ME,7,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (gf(61,9) > 0) {
		set_act_at_dist(ME,1);
		if (dist_to_pc() > 12) {
			print_str("A wingbolt hurries to catch up with you.");
			telep_char_to_char(ME,pc_num(),FALSE);
			}
			else {
				if (dist_to_pc() <= 3)
					fidget(ME,15);
					else maintain_dist_to_char(ME,pc_num(),1);
				}
		}
		
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if (gf(61,9) > 0) {
		if (dist_to_pc() > 10) {
			print_str("A wingbolt rushes back to you.");
			set_foe_target(ME,-1);
			telep_char_to_char(ME,pc_num(),FALSE);
			set_state(START_STATE);
			}

		}

	if ((what_group_in(ME) >= 0) && (sent_alert == 0) && (get_attitude(ME) >= 10)) {
		set_attitude(1000 + what_group_in(ME),10);
		alert_char(1000 + what_group_in(ME));
		set_act_at_dist(1000 + what_group_in(ME),1);
		sent_alert = 1;
		}

	do_attack();
break;


beginstate TALKING_STATE;
	if (gf(61,9) > 0) 
		print_str("Talking: The wingbolt continues to follow you. It seems completely loyal.");
		else begin_talk_mode(90);
break;